package devaluator.functionality;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Pattern;

public class Classparser extends Parser{
	
	private List<String> matched = new ArrayList<String>(); 
	
	/**
	 * @param File - a directory file 
	 */
	public Classparser(File rootDir){
		this.root=rootDir;
	}
	
	/**
	 * @param void 
	 * @return List of Strings that are matched 
	 */
	@Override
	public List<String> match() {
		String match; 
		
		walk(root);
		
		for(int j=2; j>0; j--){
			for(int i=0; i<filePaths.size(); i++){
				try{
					Pattern c;
					if(j==2){
						c= Pattern.compile(regexClass);
					}
					else{
						c= Pattern.compile(comPack);
					}
					File aFile = new File(filePaths.get(i));
				
					//pass the file to the scanner
					Scanner scanner = new Scanner(aFile);
					
					matched.add("FILE: "+aFile.getName()); 
				
					match = null;
					match=scanner.findWithinHorizon(c,0);
				
					while(match!=null){ 
						match=match.replaceAll("\\{", "");
						System.out.println(match); 
						matched.add(match);
						match=scanner.findWithinHorizon(c,0);
					}
				
				
					scanner.close();
					}catch (FileNotFoundException e){
							e.printStackTrace();
							}
				}
			}
		return matched;
		}
		
}


